package com.android.pagemarket.business.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Paper implements Serializable
{
    private static final long serialVersionUID = -521334937086009148L;
    
    public String name; // 是 C   “单坑”,“双坑”,””等等
    public List<Price> priceList;// 是   Array   价格列表
          
    public static Paper parse(JSONObject data) throws Exception
    {
        Paper one = new Paper();
        
        one.name = data.getString("name");
        JSONArray array = data.getJSONArray("priceList");
        int size = array.length();
        one.priceList = new ArrayList<Price>(size);
        for(int i=0; i<size; i++)
        {
            one.priceList.add(Price.parse(array.getJSONObject(i)));
        }
        return one;
    }
    
    public static class Price implements Serializable
    {
        private static final long serialVersionUID = 8857384483574016430L;
        
        public String paper;// 是 C 纸质
        public String price;// 是 C 单价
        public List<Brand> brandList; // 是   Array   原纸牌子列表
        public static Price parse(JSONObject data) throws JSONException
        {
            Price one = new Price();
            
            one.paper = data.getString("paper");
            one.price = data.getString("price");
            
            if(!data.isNull("brandList"))
            {
                JSONArray array = data.getJSONArray("brandList");
                int size = array.length();
                one.brandList = new ArrayList<Brand>(size);
                for(int i =0; i< size; i++)
                {
                    one.brandList.add(Brand.parse(array.getJSONObject(i)));
                }
            }
            
            return one;
        }
    }
    
    public static class Brand implements Serializable
    {
        private static final long serialVersionUID = -902365808128969183L;
        
        public String brand;// 是 C 原纸牌子
        public String params;// 是 C 参数，文本显示
        
        public static Brand parse(JSONObject data) throws JSONException
        {
            Brand one = new Brand();
            
            one.brand = data.getString("brand");
            one.params = data.getString("params");
            
            return one;
        }
    }

}